fix: prefill required plugin json fields - #34
Conversation
There was a problem hiding this comment.
Pull request overview
Improves the “Add Plugin” JSON editor experience by generating an initial plugin config template that includes schema-required fields (not just defaults), with special handling for union schemas so the prefilled JSON is closer to a valid APISIX plugin payload.
Changes:
- Refines
schemaTypeinference to avoid treating emptypropertiesas an object schema shape. - Reworks plugin “add” initialization to build a schema-driven template that prefills required fields (and recursively generates placeholders).
- Adds Playwright coverage to verify required field prefilling for a representative plugin (
limit-count).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/components/schema-form/schemaValidation.ts | Adjusts schema type inference to reduce false “object” detection when properties is empty. |
| src/components/form-slice/FormItemPlugins/PluginEditorDrawer.tsx | Implements required-field-aware template generation for plugin add flow (including union/placeholder logic). |
| e2e/tests/resource-required-templates.spec.ts | Adds an e2e test asserting plugin add JSON prefills required fields from APISIX schema. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const matchingVariants = [ | ||
| ...(resolvedSchema.oneOf ?? []), | ||
| ...(resolvedSchema.anyOf ?? []), | ||
| ].filter( | ||
| (variant) => validateSchemaValue(variant, value, '', rootSchema).length === 0 | ||
| ); | ||
| const unionVariants = [ | ||
| ...(resolvedSchema.oneOf ?? []), | ||
| ...(resolvedSchema.anyOf ?? []), | ||
| ]; | ||
| if (matchingVariants.length === 0 && unionVariants[0]) { | ||
| for (const key of getActiveRequiredFields(unionVariants[0], value, rootSchema)) { | ||
| required.add(key); | ||
| } | ||
| collectTemplateRequiredFields(unionVariants[0], value, rootSchema, required); | ||
| } |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2dbb899eb9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (type === 'string' && resolvedSchema.minLength && resolvedSchema.minLength > 0) { | ||
| return 'value'; |
There was a problem hiding this comment.
Honor minLength when generating required strings
When an APISIX or custom plugin schema marks a string field as required with minLength greater than 5, this branch seeds it with the fixed string value. The add-mode JSON template then fails the drawer's own validateSchemaValue check and cannot be saved until the user edits a field that was supposed to be prefilled; generate a string at least minLength characters long or otherwise respect the constraint.
Useful? React with 👍 / 👎.
Summary
Verification